{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "## 第一次使用SSH 连接 Centos 需要验证的密钥host-key\n",
    "# 参考链接：https://en.wikibooks.org/wiki/OpenSSH%2FCookbook%2FPublic_Key_Authentication\n",
    "# ```````````````````````````````````````````````````````````````````````````````````\n",
    "$ ssh -l fred server.example.org\n",
    "# The authenticity of host 'server.example.org (192.0.32.10)' can't be established.\n",
    "# ECDSA key fingerprint is SHA256:LPFiMYrrCYQVsVUPzjOHv+ZjyxCHlVYJMBVFerVCP7k.\n",
    "# Are you sure you want to continue connecting (yes/no)?\n",
    "\n",
    "## 默认使用base64 encoded SHA256， 可指定MD5编码\n",
    "# ```````````````````````````````````\n",
    "$ ssh -o FingerprintHash=md5 host.example.org\n",
    "# The authenticity of host 'host.example.org (192.0.32.203)' can't be established.\n",
    "# RSA key fingerprint is MD5:10:4a:ec:d2:f1:38:f7:ea:0a:a0:0f:17:57:ea:a6:16.\n",
    "# Are you sure you want to continue connecting (yes/no)?\n",
    "# 下载签名的host-key\n",
    "`````````````\n",
    "#例如：ssh-keyscan 172.19.6.177\n",
    "$ ssh-keyscan host.example.org\n",
    "# host.example.org SSH-2.0-OpenSSH_7.2\n",
    "host.example.org ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBLC2PpBnFrbXh2YoK030Y5JdglqCWfozNiSMjsbWQt1QS09TcINqWK1aLOsNLByBE2WBymtLJEppiUVOFFPze+I=\n",
    "# host.example.org SSH-2.0-OpenSSH_7.2\n",
    "host.example.org ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC9iViojCZkcpdLju7/3+OaxKs/11TAU4SuvIPTvVYvQO32o4KOdw54fQmd8f4qUWU59EUks9VQNdqf1uT1LXZN+3zXU51mCwzMzIsJuEH0nXECtUrlpEOMlhqYh5UVkOvm0pqx1jbBV0QaTyDBOhvZsNmzp2o8ZKRSLCt9kMsEgzJmexM0Ho7v3/zHeHSD7elP7TKOJOATwqi4f6R5nNWaR6v/oNdGDtFYJnQfKUn2pdD30VtOKgUl2Wz9xDNMKrIkiM8Vsg8ly35WEuFQ1xLKjVlWSS6Frl5wLqmU1oIgowwWv+3kJS2/CRlopECy726oBgKzNoYfDOBAAbahSK8R\n",
    "# host.example.org SSH-2.0-OpenSSH_7.2\n",
    "host.example.org ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDDOmBOknpyJ61Qnaeq2s+pHOH6rdMn09iREz2A/yO2m\n",
    "`````````````````````````````````````````````````````````````````````````````````````````````````\n",
    "\n",
    "## Linux 中 iptables 的设置\n",
    "\n",
    "# 1. 将iptables 配置保存在``/etc/sysconfig/iptables``\n",
    "service iptables save\n",
    "# 2. 配置iptables文件，注意不能restart iptables，可以执行start 或 reload\n",
    "service iptables reload #或\n",
    "service iptables start  #如果在修改配置之前stop 了iptables\n",
    "\n",
    "# 恢复iptables 备份配置：\n",
    "# 复制`xtcAuto\\doc\\deployment\\iptables.conf`即可得到最基本的配置，允许 docker,jenkins，saltstack,java,nginx 业务。\n",
    "# All the solutions based in eval() are dangerous, malicious code could be injected inside the string and get executed.\n",
    "# According to the documentation the expression gets evaluated safely. Also, according to the source code, literal_eval parses the string to a python AST (source tree), and returns only if it is a literal. The code is never executed, only parsed, so there is no reason for it to be a security risk.\n",
    "\n",
    "# Nmap 用法\n",
    "# ------------------------------------------------------------------\n",
    "# 1. 扫描网段\n",
    "nmap -sP -PR 192.168.0.*\n",
    "\n",
    "# Npm Registry\n",
    "# 淘宝可选，但是不可靠\n",
    "# If you're in China, maybe you should install it from our China mirror:\n",
    "# ------------------------------------------------------------------\n",
    "\n",
    "$ npm install cnpm -g --registry=https://registry.npm.taobao.org\n",
    "\n",
    "\n",
    "## bash 获取文件或重定向的第一行\n",
    "# ````````````````````\n",
    "$ head -n1 file\n",
    "$ sed -n 1p file\n",
    "$ awk 'NR == 1' file"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500\n",
      "        inet 172.18.5.179  netmask 255.255.240.0  broadcast 172.18.15.255\n",
      "        ether 00:16:3e:04:6a:9f  txqueuelen 1000  (Ethernet)\n",
      "        RX packets 69318  bytes 21224487 (20.2 MiB)\n",
      "        RX errors 0  dropped 0  overruns 0  frame 0\n",
      "        TX packets 58161  bytes 39870510 (38.0 MiB)\n",
      "        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0\n",
      "\n"
     ]
    }
   ],
   "source": [
    "ifconfig eth0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "bash: tree: command not found\n"
     ]
    },
    {
     "ename": "",
     "evalue": "127",
     "output_type": "error",
     "traceback": []
    }
   ],
   "source": [
    "# tree\n",
    "# Linux tree命令用于以树状图列出目录的内容。\n",
    "# 执行tree指令，它会列出指定目录下的所有文件，包括子目录里的文件。\n",
    "tree /home"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# CPU状态查看\n",
    "period=100000\n",
    "n=$((6*1000000/$period))\n",
    "i=0\n",
    "{\n",
    "while [ $i -lt $n ]\n",
    "do\n",
    "d=$(date)\n",
    "echo $d 1>&2 \n",
    "top -n 1 |awk -v date=\"$d\" '/Xorg/{print $10\";\"$13\" \"date}'\n",
    "i=$(($i+1))\n",
    "usleep $period\n",
    "done \n",
    "} | tee >(awk -F\\; '{if($1>=max){max=$1;proname=$2}}END{print max\";\"proname}')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Bash",
   "language": "bash",
   "name": "bash"
  },
  "language_info": {
   "codemirror_mode": "shell",
   "file_extension": ".sh",
   "mimetype": "text/x-sh",
   "name": "bash"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
